<?php
/**
 * Created by PhpStorm.
 * User: 65736
 * Date: 2019/3/9 0009
 * Time: 16:46
 */

namespace app\common\widget;

class WidgetTableColumn extends WidgetCommon
{
    /**
     * 列Title
     * @var string
     */
    private $title;

    /**
     * 列字段
     * @var string
     */
    private $field = "";


    /**
     * 构造方法, 渲染挂件
     * @return mixed
     * @throws \think\Exception
     */
    function render()
    {
        if ( is_null($this->title) ) $this->throwException( "没有设置Title" );
        self::$view->assign("title", $this->title);
        self::$view->assign("field", $this->field);
        return $this->fetch();
    }

    /**
     * 设置列标题
     * @param $title
     * @return $this
     * @throws \think\Exception
     */
    public function setColTitle( $title ) {
        if ( !$title ) $this->throwException( "Table列挂件没有标题" );
        $this->title = $title;
        return $this;
    }

    /**
     * 设置列字段
     * @param string $field
     * @return $this|WidgetCommon
     * @throws \think\Exception
     */
    public function setColField( $field ) {
        if ( !$field ) $this->throwException( "Table列挂件没有设置字段" );
        $this->field = $field;
        return $this;
    }

    /**
     * @return string
     */
    public function getField(): string
    {
        return $this->field;
    }

    /**
     * @return string
     */
    public function getTitle(): string
    {
        return $this->title;
    }


}